package com.example.a.controller;

import com.example.a.entity.OrderDetail;
import com.example.a.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order-detail")
@CrossOrigin(origins = "*", allowedHeaders = "*")
public class OrderDetailController {

    @Autowired
    private OrderDetailService orderDetailService;

    @GetMapping("/{orderId}")
    public List<OrderDetail> getAllByOrderId(@PathVariable String orderId) {
        return orderDetailService.findAllByOrderId(orderId);
    }

    @PostMapping
    public String insert(@RequestBody OrderDetail orderDetail) {
        orderDetailService.insert(orderDetail);
        return "Order detail inserted successfully";
    }
}